package com.imooc.grace.result;

public class ResponseJSONResult<T> {

    // 响应业务状态
    private Integer status;

    // 响应消息
    private String msg;

    // 响应中的数据
    private T data;

    private boolean success;	// 不使用

    public static ResponseJSONResult exception(ResponseStatusEnum responseStatus) {
        return new ResponseJSONResult(responseStatus);
    }


    public static <T> ResponseJSONResult build(Integer status, String msg, T data) {
        return new ResponseJSONResult(status, msg, data);
    }

    public static <T> ResponseJSONResult build(Integer status, String msg, T data, boolean ok) {
        return new ResponseJSONResult(status, msg, data, ok);
    }

    public static <T> ResponseJSONResult ok(T data) {
        return new ResponseJSONResult(data);
    }

    public static ResponseJSONResult ok() {
        return new ResponseJSONResult(200, "OK", null, true);
    }

    public static ResponseJSONResult errorMsg(String msg) {
        return new ResponseJSONResult(500, msg, null);
    }

    public static ResponseJSONResult errorUserTicket(String msg) {
        return new ResponseJSONResult(557, msg, null);
    }

    public static <T> ResponseJSONResult errorMap(T data) {
        return new ResponseJSONResult(501, "error", data);
    }

    public static ResponseJSONResult errorTokenMsg(String msg) {
        return new ResponseJSONResult(502, msg, null);
    }

    public static ResponseJSONResult errorException(String msg) {
        return new ResponseJSONResult(555, msg, null);
    }

    public static ResponseJSONResult errorUserQQ(String msg) {
        return new ResponseJSONResult(556, msg, null);
    }

    public ResponseJSONResult() {

    }

    public ResponseJSONResult(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public ResponseJSONResult(Integer status, String msg, T data, boolean success) {
        this.status = status;
        this.msg = msg;
        this.data = data;
        this.success = success;
    }

    public ResponseJSONResult(T data) {
        this.status = 200;
        this.msg = "OK";
        this.data = data;
    }

    public ResponseJSONResult(ResponseStatusEnum responseStatusEnum) {
        this.status = responseStatusEnum.status();
        this.msg = responseStatusEnum.msg();
        this.data = null;
        this.success = responseStatusEnum.success();
    }

    public Boolean isOK() {
        return this.status == 200;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }
}
